package com.CoviMobileApp;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;


public class TripleDesImplementation {
	private String key;
	private String initializationVector;
	
	public TripleDesImplementation(String key, String initializationVector)
	{
		this.key = key;
		this.initializationVector = initializationVector;
	}

	public String encryptText(String plainText) throws Exception{
	//----  Use specified 3DES key and IV from other source -------------------------
		byte[] plaintext = plainText.getBytes();
		byte[] tdesKeyData = key.getBytes();

		byte[] myIV = initializationVector.getBytes(); 


		Cipher c3des = Cipher.getInstance("DESede/CBC/PKCS5Padding");
		SecretKeySpec    myKey = new SecretKeySpec(tdesKeyData, "DESede");
		IvParameterSpec ivspec = new IvParameterSpec(myIV);

		c3des.init(Cipher.ENCRYPT_MODE, myKey, ivspec);
		byte[] cipherText = c3des.doFinal(plaintext);
		return Base64.encodeBytes(cipherText);
		//return Base64Coder.encodeString(new String(cipherText));
	}
}
